from django.test import TestCase

# Create your tests here.
# 随机选择12个字符串
def get_key():
    import random
    base_str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz0123456789'
    name = ''.join(random.sample(base_str, 12))
    return name
# 随机选择一个字符串
def get_new_key():
    import random
    base_str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz0123456789'
    return random.choice(base_str)
# print(get_new_key())
# 测试相关文件操作
# import os
# base_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# upfile_dir = os.path.join(base_path,'upload_file')
# write_path = upfile_dir + '/test'
# is_have = os.path.exists(write_path)
# if not is_have:
#     os.makedirs(write_path)

# 获取本机IP的测试
import socket
myname = socket.getfqdn(socket.gethostname())
myip = socket.gethostbyname(socket.gethostname())
print(myname)
print(myip)

import socket

def get_host_ip():
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.connect(('8.8.8.8', 80))
        ip = s.getsockname()[0]
    finally:
        s.close()
    return ip

print(get_host_ip())